package com.weiyan.blog.controller;

import com.weiyan.blog.feign.CommFeign;
import com.weiyan.blog.response.Result;
import com.weiyan.blog.response.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @author misterWei
 * @create 2020年01月19号:23点46分
 * @mailbox mynameisweiyan@gmail.com
 */
@CrossOrigin
@RestController
@RefreshScope
@RequestMapping("oa")
public class OaController {
    @Value("${test}")
    private String test;

    @Autowired
    private CommFeign commFeign;

    @RequestMapping(value = "/init",method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('sys')") //在之前方法级别拦截
    public Result init(){

        ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        RequestContextHolder.setRequestAttributes(sra, true);
        return new Result(ResultCode.SUCCESS,commFeign.index());
    }
}
